<?php

/**
 * 文件注释
 *
 * 小程序控制器
 *
 * Author: Liam
 * Datetime: 12/28/18 00:00 PM
 */

namespace ApiBundle\Controller;

use BaseBundle\Controller\BaseController;
use Symfony\Component\HttpFoundation\Request;


class XcxController extends BaseController
{
    /**
     * 登录
     *
     * @param Request $request
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     */
    public function xcxLoginAction(Request $request)
    {
        $token = $request->get('token');

        if ($token == '' || $token == null) {
            return $this->jsonResponse('登录失效，请重新登录', 401);
        }
    }

    /**
     * 首页数据
     *
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     */
    public function xcxIndexAction()
    {
        $conn = $this->get('database_connection');

        $banner = $conn->fetchAll("SELECT * FROM banner");
        $list = $conn->fetchAll("SELECT * FROM goods WHERE is_index=1");

        $data = Array(
            'banner'=> $banner,
            'list' => $list
        );

        return $this->jsonResponse('获取成功', 0, $data);
    }

    /**
     * 获取商品分类
     *
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     */
    public function xcxGoodsTypeAction()
    {
        $conn = $this->get('database_connection');
        $list = $conn->fetchAll("SELECT * FROM goods_classify");
        $data = Array(
            'list' => $list
        );

        return $this->jsonResponse('获取成功', 0, $data);
    }

    /**
     * 通过商品分类获取商品列表
     *
     * @param Request $request
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     */
    public function xcxGoodsListAction(Request $request)
    {
        $id = $request->get('id');

        if ($id == '') {
            return $this->jsonResponse('参数异常', 1);
        }
        $conn = $this->get('database_connection');
        $list = $conn->fetchAll("SELECT * FROM goods WHERE goods_classify_id='.$id.'");
        $data = Array(
            'list' => $list
        );

        return $this->jsonResponse('获取成功', 0, $data);
    }

    /**
     * 商品详情
     *
     * @param Request $request
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     */
    public function xcxGoodsInfoAction(Request $request)
    {
        $id = $request->get('id');

        if ($id == '') {
            return $this->jsonResponse('参数异常', 1);
        }
        $conn = $this->get('database_connection');
        $list = $conn->fetchAssoc("SELECT * FROM goods WHERE id='.$id.'");
        $data = Array(
            'list' => $list
        );

        return $this->jsonResponse('获取成功', 0, $data);
    }


}